sacktankluafandomcom-20200214-history
Community Curator/Source/TSWRes Community
Community = {} Community.SavedFile= {} SavedFile = Community.SavedFile local SavedFile = Community.SavedFile SavedFile"CommunityLevels" = {} SFJSON = SavedFile.SFJSON Community.ConnectURL = "http://sacktanklua.wikia.com/" Community.SignInURL = "wiki/Special:UserLogin" Community.SignOutURL = "wiki/Special:UserLogout" Community.SignUpURL = "wiki/Special:UserSignup" Community.PageStart = "CommunityScriptStart" HS = 32 print(http) local http if not http then http = require "TSWRes HTTP" end Key = require "TSKeyboard" Community.Username = "Guest" CommunityPage = {} CommunityPage"InfoBox" = {} local InfoBox = CommunityPage"InfoBox" InfoBox1="If you see this, you are not" InfoBox2="connected!" function Community.LoadFile() if not FS.exists("LBPCommunitySave.data") then Community.ShowIntro = true Community.FirstUse = true return true, "No file found" end local SavedFile = Community.SavedFile local FileHandle = io.open("LBPCommunitySave.data") if not FileHandle then Community.ShowIntro = true Community.FirstUse = true return false, "Failed to load file" end Community.ShowIntro = FileHandle:read() if Community.ShowIntro "1" then Community.ShowIntro = true end FileHandle:close() SavedFile.SFJSON = {} SFJSON = SavedFile.SFJSON SFJSON"CommunityLevels" = {} local CL = SFJSON"CommunityLevels" CL"Levels"=0 CL"SavedLevelTab" = {} print(CL) if not FS.exists("LBPCommunitySave.JSON") then return true, "No JSON file found" end local FileHandle2 = io.open("LBPCommunitySave.JSON") if FileHandle2 then local SFS = FileHandle2:read() print(SFS) FileHandle2:close() if type(SFS) "string" then SavedFile.SFJSON = JSON.DecodeJSON(SFS) if type(SavedFile.SFJSON) "string" then print(SFJSON) return false, "error loading JSON" elseif type(SavedFile.SFJSON) ~= "table" then print("Error while loading Community") return false, "error loading JSON" end --CL"Levels"=0 --CL"SavedLevelTab" = {} local SLTab = CL"SavedLevelTab" if not CL"SavedLevelTab" then print("error detected while loading Community Levels") return false, "Community Levels error" end for k, v in ipairs(CL"SavedLevelTab") do v"Size" = GT.LevelSize(k) if not ok then --table.remove( MyMoonLevels"SavedLevelTab", k) end end --[(BLs >= #CL["SavedLevelTab" and BLs ~= 0) then print("Only Broken Levels found!") return "error" end]] else return true, "error" end else SavedFile.SFJSON = {} local SFJSON = SavedFile.SFJSON SFJSON"CommunityLevels" = {} local CL = SFJSON"CommunityLevels" CL"Levels"=0 CL"SavedLevelTab" = {} return false, "Community JSON File is unloadable" end print("Community Savefile Loaded") return true end function Community.Intro() draw.beginframe() Draw.BGs.CommunityIntro() draw.endframe() draw.waittouch() draw.beginframe() Draw.BGs.CommunityIntro1() draw.endframe() draw.waittouch() end function Community.Disconnect() Community.SignOut() Community.Connected = false end function Community.Connect() Community.ConnectProg = 0 Community.ConnectStage = "Connecting to the Community Moon..." draw.beginframe() Draw.BGs.CommunityConnectProg() draw.endframe() SX, SY = draw.getport() local ConnectTest = http.load(Community.ConnectURL) Community.Connected = true return true end function Community.Connect2() -- Moderate Community.ConnectProg = 20 Community.ConnectStage = "Moderating..." draw.beginframe() Draw.BGs.CommunityConnectProg() draw.endframe() print("Moderating") -- Download Community Data sleep(1000) Community.ConnectProg = 40 Community.ConnectStage = "Downloading Community Data..." draw.beginframe() Draw.BGs.CommunityConnectProg() draw.endframe() print("Downloading Community Data") -- Upload Offline Data sleep(1000) Community.ConnectProg = 60 Community.ConnectStage = "Uploading Offline Data..." draw.beginframe() Draw.BGs.CommunityConnectProg() draw.endframe() print("Uploading Offline Data") -- Almost done sleep(1000) Community.ConnectProg = 80 Community.ConnectStage = "Almost done..." draw.beginframe() Draw.BGs.CommunityConnectProg() draw.endframe() sleep(1000) Community.FullyConnected = true return true end function Community.SignIn() local Resp = http.load(Community.ConnectURL ..Community.SignInURL) local UserName, Password --if Resp "Sign in" then UserName = Key.Keyboard("Username") Password = Key.Keyboard("Password") --end Community.Username = UserName Community.SignedIn = true return true end function Community.SignOut() http.load(Community.ConnectURL ..Community.SignOutURL) Community.Username = "Guest" Community.SignedIn = false end function Community.SaveFile() local FileHandle = io.open("LBPCommunitySave.data", "w") FileHandle:write("0") FileHandle:close() local FileHandle2 = io.open("LBPCommunitySave.JSON", "w") local SaveString = JSON.EncodeJSON(SavedFile.SFJSON) print(SaveString) FileHandle2:write(SaveString) FileHandle2:close() end function Community.Download(Level) end function Community.FirstConnect() print("This is your first time connecting to the servers.") if Community.Connect() true then print("Connected to the severs.") end Community.Connect2() local FileHandle = io.open("LBPCommunitySave.data", "w") FileHandle:write("0") FileHandle:close() Community.OnlineMenuHomeSO() return end Community.ConnectToCommunity = Community.FirstConnect require "TSWRes Community1" require "TSWRes CommunityDraw" require "TSWRes CommunityPlayIcons" return Community